//
//  LDXTabBarController.swift
//  微博
//
//  Created by 吕东星 on 17/3/26.
//  Copyright © 2017年 lddongxing. All rights reserved.
//

import UIKit

class LDXTabBarController: UITabBarController,LDXTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
       
        //使用kvc来使用自定义tabbar
//      self.tabBar = LDXTabBar
        let ltabbar = LDXTabBar()
        
        //设置代理
        ltabbar.LDXDelegate = self;
       
        //设置闭包
        ltabbar.didSelectedComposeButtonAction = { [weak self] in
         
            print("闭包方法调用")
        }
        
        self.setValue(ltabbar, forKey: "tabBar")
        
//      view.backgroundColor = UIColor.yellow
        
      addChildViewController(childController: HomeTableViewController(), imageName: "tabbar_home", title: "首页")
      addChildViewController(childController: MessageTableViewController(), imageName: "tabbar_message_center_selected", title: "消息")
      addChildViewController(childController: DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
      addChildViewController(childController: MineTableViewController(), imageName: "tabbar_profile", title: "我的")
        
    }
    func didComposeButtonAction() {
        print("代理方法调用")
    }
    
    
    // 添加自控制器,添加背景
    func addChildViewController(childController: UIViewController,imageName: String,title: String) {
        
        childController.tabBarItem.image = UIImage(named:imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: .normal)
//        childController.tabBarItem.title = title
//        childController.navigationItem.title = title
        childController.title = title
        
        let nav = LDXNavViewController(rootViewController: childController)
        addChildViewController(nav)
    }
}
